package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.*;
import com.ruoyi.logistic.service.NetworkCostTicketService;
import com.ruoyi.logistic.service.NetworkManEffectService;
import com.ruoyi.logistic.service.NetworkPostEffectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/network/manEffectStatistic")
@RestController
@Api(tags = "网点财务_人效统计分析")
public class NetworkManEffectStatisticController {
    @Autowired
    private NetworkPostEffectService networkPostEffectService;
    @Autowired
    private NetworkCostTicketService networkCostTicketService;
    @Autowired
    private NetworkManEffectService networkManEffectService;

    @ApiOperation("显示岗位人效")
    @GetMapping("/selectPostEffectAll")
    public R selectAll(){
        List<NetworkPostEffect> effectList = networkPostEffectService.selectAll();
        if (effectList == null || effectList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(effectList);
        }
    }

    @ApiOperation("添加岗位人效")
    @PostMapping("/insertPostEffect")
    public R insert(@RequestBody NetworkPostEffect networkPostEffect){
        Boolean isAdd = networkPostEffectService.insert(networkPostEffect);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }

    @ApiOperation("修改岗位人效")
    @PostMapping("/updatePostEffect")
    public R update(@RequestBody NetworkPostEffect networkPostEffect){
        Boolean isUpdate = networkPostEffectService.update(networkPostEffect);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }

    @ApiOperation("删除岗位人效")
    @PostMapping("/deletePostEffectById")
    public R deleteById(Integer id){
        Boolean isDelete = networkPostEffectService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }

    @ApiOperation("显示单票成本")
    @GetMapping("/selectCostTicketAll")
    public R selectCostTicketAll(){
        List<NetworkCostTicket> costTicketList = networkCostTicketService.selectAll();
        if (costTicketList == null || costTicketList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(costTicketList);
        }
    }

    @ApiOperation("添加单票成本")
    @PostMapping("/insertCostTicket")
    public R insertCostTicket(@RequestBody NetworkCostTicket networkCostTicket){
        Boolean isAdd = networkCostTicketService.insert(networkCostTicket);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }

    @ApiOperation("修改单票成本")
    @PostMapping("/updateCostTicket")
    public R updateCostTicket(@RequestBody NetworkCostTicket networkCostTicket){
        Boolean isUpdate = networkCostTicketService.update(networkCostTicket);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }

    @ApiOperation("删除单票成本")
    @PostMapping("/deletePostCostTicketId")
    public R deleteByCostTicketId(Integer id){
        Boolean isDelete = networkCostTicketService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }

    @ApiOperation("工资发放总额")
    @GetMapping("/grossPayroll")
    public R collect(PageDate pageDate){
        List<NetworkGrossPayroll> grossPayrollList = networkManEffectService.collect(pageDate);
        if (grossPayrollList == null || grossPayrollList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(grossPayrollList));
        }
    }

    @ApiOperation("人效统计")
    @GetMapping("/collectManEffect")
    public R collectManEffect(String month){
        return R.ok(networkManEffectService.collectManEffect(month));
    }
}
